from sqlalchemy import Enum, ForeignKey
from sqlalchemy.orm import Mapped, mapped_column, relationship

from tinkoff_bot.core.models.enums.bill import BillStatus, PaymentMethod
from .base import TimedBaseModel


class Bill(TimedBaseModel):
    __tablename__ = "bill"
    __mapper_args__ = {"eager_defaults": True}

    id: Mapped[int] = mapped_column(primary_key=True)
    payment_method: Mapped[PaymentMethod] = mapped_column(Enum(PaymentMethod))
    summ: Mapped[float]
    invoice_id: Mapped[str]
    status: Mapped[BillStatus] = mapped_column(Enum(BillStatus), default=BillStatus.waiting_payment)
    user = relationship("User", back_populates="bills")
    user_id: Mapped[int] = mapped_column(ForeignKey("user.id"))

    def __repr__(self):
        return f"<Счет №{self.id} на сумму {self.summ}$>"

    def __str__(self):
        return self.__repr__()
